#conding=utf-8
import ddt
import unittest
import sys
sys.path.append("D:/seleniumpython")
from selenium import webdriver
from business.register_business import RegisterBusiness
from util.excel_util import ExcelUtil
import time
import HTMLTestRunner
import os
ex = ExcelUtil()
data = ex.get_data()
@ddt.ddt
#手机号码、图片验证码、手机验证码、输入密码、确认密码,错误信息定位元素、错误提示信息
class FristDdtCase(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.get("http://my.caissa.com.cn/Registered/index")
        self.driver.maximize_window()
        self.register_b = RegisterBusiness(self.driver)
        time.sleep(2)
    
    def tearDown(self):
        time.sleep(2)
        for method_name,error in self._outcome.errors:
            if error:
                case_name = self._testMethodName
                file_path = os.path.join(os.getcwd()+"/report/"+case_name+".png")
                self.driver.save_screenshot(file_path)
                
        self.driver.close()
    '''    
    @ddt.data( 
        ['021-52835638','code','1234','qiao2012','qiao2012','phone_error','格式有误，请重新输入'],
        ['13524559840','code','1234','qiao2012','qiao2012','code_error','验证码错误'],
        # ['13524559840','code','1234','qiao2012','qiao2012','phone_code_error','验证码错误，请重新填写'],
        ['13524559840','code','1234','qiao2012','qiao2012','password_error','格式有误，请重新输入。'],
        # ['13524559840','code','1234','qiao2012','123456789','confirm_password_error','密码不一致，请重新输入。'],
        )
    @ddt.unpack
    '''
    @ddt.data(*data)
    def test_register_case(self,data):
        phone,code,phone_code,password,confirm_password,assertCode,assertText = data
        phone_error = self.register_b.register_function(phone,code,phone_code,password,confirm_password,assertCode,assertText)
        #电话号码错误没有找到，就算注册成功了，但是case用例执行失败了
        self.assertFalse(phone_error,'测试失败')

if __name__ == "__main__":
    fiel_path = os.path.join(os.getcwd()+"/report/"+"frist_case1.html")
    f = open(fiel_path,'wb')
    suite = unittest.TestLoader().loadTestsFromTestCase(FristDdtCase)
    runder = HTMLTestRunner.HTMLTestRunner(stream=f,title="This is frist register",description="这是第一个注册case1")
    runder.run(suite)